package com.nc.delivery_project.server.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.nc.delivery_project.server.dao.AbstractDao;
import com.nc.delivery_project.server.dao.CountryDao;
import com.nc.delivery_project.server.dao.UserDao;
import com.nc.delivery_project.server.db_util.ConnectionManager;
import com.nc.delivery_project.server.domain.Country;
import com.nc.delivery_project.server.domain.Role;
import com.nc.delivery_project.server.domain.StateProvince;
import com.nc.delivery_project.server.util.CRUD;



public class CountryService extends BaseService<Country> {
	

	public CountryService() {
		this(new CountryDao());
	}
	
	
	public CountryService(AbstractDao<Country> countryDao) {
		super(countryDao);
	}



	public CountryService(Connection connection, boolean isAutoCloseConnection) {
        super(new CountryDao(), connection, isAutoCloseConnection);
	}


	

	@Override
	public List<Country> read() {
		
		List<Country> coutnries =  null;
        try {
        	 Connection conn = getConnection();
             dao.setConnection(conn);
             coutnries = dao.read();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                closeConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return coutnries;
	}

	@Override
	public Country read(int id) {
		
		Country country = null;
        try {
        	 Connection conn = getConnection();
             dao.setConnection(conn);
             country = dao.read(id);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                closeConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return country;
	}



	public List<StateProvince> loadCountryStateProvince(int countryId){
		List<StateProvince> states = new StateProvinceService().loadStatePrByCountryId(countryId);
		return states ;
	}
	
	
	
}
